#include "ImageHolder.h"

ImageHolder::ImageHolder (Image * img) : size (32),
							  image (img),
							  isMouseDown (false)
{

	int w = image->getWidth();
	int h = image->getHeight();

	setSize((int) (w * size / h), size);
	this->setInterceptsMouseClicks(false, false);

	setInterceptsMouseClicks(false, false);
	
}
    
ImageHolder::~ImageHolder()
{
	deleteAllChildren();
	if(image)
		delete image;
}

void ImageHolder::paint (Graphics& g)
{
	if(isMouseDown)
		g.setOpacity(.6f);

	g.drawImageWithin(image, 0,0, getWidth(), getHeight(), RectanglePlacement::centred);

	//image->drawWithin(g, 0, 0, getWidth(), getHeight(), RectanglePlacement::centred);
}
    
void ImageHolder::resized()
{
	//if(getParentComponent()->isValidComponent())
	//	getParentComponent()->resized();
}

void ImageHolder::setMouseDown(const bool& down)
{
	isMouseDown = down;
	repaint();
}